
//% color="#1296db" iconWidth=50 iconHeight=40
namespace ltr390uv {

    //% block="初始化LTR390UV传感器 I2C地址0x1C" blockType="command"
    export function init(parameter: any, block: any) {
        Generator.addImport("from DFRobot_LTR390UV import *");
        Generator.addImport("import time");
        Generator.addImport("import sys");
        Generator.addDeclaration("set_etime","LTR390_etime=e25ms",true)
        Generator.addDeclaration("set_erate","LTR390_erate=e20bit",true)
        Generator.addDeclaration("set_egain","LTR390_egain=eGain1",true)
        Generator.addCode(`LTR390UV = DFRobot_LTR390UV_I2C(bus=1,addr=0x1c)`);
        Generator.addCode(`  
while (LTR390UV.begin() == False):
    print("Sensor initialize failed!!")
    time.sleep(1)
print("Sensor  initialize success!!")`);
 
    }

    //% block="设置传感器数据位[RATE]" blockType="command"
    //% RATE.shadow="dropdown" RATE.options="RATE"
    export function setALSOrUVSMeasRate(parameter: any, block: any) {
        let rate=parameter.RATE.code;
        Generator.addDeclaration("set_erate",`LTR390_erate=${rate}`,true)
        Generator.addCode(`LTR390UV.set_ALS_or_UVS_meas_rate(LTR390_erate,LTR390_etime)`);
 
    }

    //% block="设置传感器的增益倍数为[GAIN] 采样时间[TIME]" blockType="command"
    //% GAIN.shadow="dropdown" GAIN.options="GAIN" 
    //% TIME.shadow="dropdown" TIME.options="TIME" 
    export function setALSOrUVSGain(parameter: any, block: any) {
        let gain=parameter.GAIN.code;
        let time=parameter.TIME.code;
        Generator.addDeclaration("set_egain",`LTR390_egain=${gain}`,true)
        Generator.addDeclaration("set_etime",`LTR390_etime=${time}`,true)
        Generator.addCode(`LTR390UV.set_ALS_or_UVS_gain(LTR390_egain)`);
 
    }
    
    //% block="设置传感器的识别模式为[MODE]" blockType="command"
    //% MODE.shadow="dropdown" MODE.options="MODE" 
    export function setmode(parameter: any, block: any) {
        let mode=parameter.MODE.code;
        Generator.addCode(`LTR390UV.set_mode(${mode})`);
 
    }

    //% block="获取传感器的[MOD]" blockType="reporter"
    //% MOD.shadow="dropdown" MOD.options="MOD" 
    export function getData(parameter: any, block: any) {
        let mod=parameter.MOD.code;
        Generator.addCode(`LTR390UV.${mod}()`);
 
    }



 
}
